package com.lagou.client;

import com.lagou.component.RegisterClient;
import com.lagou.request.RpcRequest;

import com.lagou.response.RpcResponse;
import java.util.UUID;

public class ClientBootStrap {

    private static RegisterClient registerClient = new RegisterClient();

    public static void main(String[] args) throws InterruptedException {
        while (true){
            try {
                RpcConsumer rpcConsumer = registerClient.getRpcConsumer();
                RpcRequest request = new RpcRequest();
                request.setRequestId(UUID.randomUUID().toString());
                request.setClassName("UserService");
                request.setMethodName("sayHello");
                request.setParameters(new Object[]{"I'm client"});
                request.setParameterTypes(new Class[]{String.class});
                RpcResponse rpcResponse = (RpcResponse) rpcConsumer.invoke(request);
                if (rpcResponse.getCode().equals(RpcResponse.OK)) {
                    System.out.println("调用成功，返回参数：" + rpcResponse.getData().toString());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            Thread.sleep(4000);
        }
    }
}

